package com.zdy.boot.upload.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

/**
 * @author sdy
 * @description
 * @date 2025/2/9
 */
@Slf4j
public class FileUtils {

    public static boolean filter(Path path, String fileType) {
        return Files.isRegularFile(path) && path.getFileName().toString().endsWith(fileType);
    }

    public static void delete(List<Path> paths) {
        if (CollectionUtils.isEmpty(paths)) {
            return;
        }
        paths.forEach(FileUtils::delete);
    }

    public static void delete(Path path) {
        try {
            Files.deleteIfExists(path);
        } catch (IOException e) {
            path = null;
        }
    }

}
